The interactive web is built on JavaScript, from interactive bar charts like the one below (move your cursor over the barchart) to the interactive maps provided by Google, Bing and other services. There is a relatively simple way to build these interactive charts directly from R and to host these online via RPubs, GitHub Pages or to include such interactive data visualisations within a Shiny app. Note that the specific code for this interactive chart is available in the XXXXXXBARCHARTXXX section.

In order to generate these charts, R must generate the requisite HTML and JavaScript code for the visualisations. The RStudio company has made this process easy by developing a library called htmlwidgets which acts as a framework for building JavaScript bindings - which simply means:

htmlwidgets provides standardised tools to build secondary R packages that bind to JavaScript libraries, the functions in these R packages can be used to generate the same output the original JavaScript library would

A popular visualisation library used in this tutorial is plot.ly, the developers for plot.ly have created a library using htmlwidgets called plotly that allows interactive charts, maps and more to be generated directly from R code. Note that if you are following along with the code samples in this document you are advised to use RStudio which provides a built-in web viewer within which visualisations can be seen. The code below generates an interactive scatterplot using the plotly.js library:

library(plotly)
library(gapminder)
plot_ly(data = gapminder,
        x = gapminder$year,
        y = gapminder$lifeExp,
        group = gapminder$continent,
        text = gapminder$country,
        mode = "markers")

What’s in this guide?

There are over 15 CRAN-hosted libraries that utilise htmlwidgets for creating interactive content, the majority of these libraries are well documented at htmlwidgets.org. The documentation at htmlwidgets.org is focused on individual libraries, it does not attempt to group them or compare the utility of the different libraries for specific types of charts.

This document is designed to address the following questions:

  • Which library is capable of making chart X?
  • Which charts can be made with library X?
  • How do these charts compare against one another?

An interactive breakdown of the libraries is provided in the section below, however note that it is not the intention of this document to cover all available htmlwidget libraries - only those that have been used in the Live Data project

Comparison of htmlwidgets

In order to compare htmlwidget libraries we must define a set of visualisations and visualisation categories:

  • Charts: for comparatie visualisations
  • Nerworks: connections
  • Maps: maps

Shiny apps to achieve the following:

  • What types of visualisations can be made by what library?
  • How are visualisations grouped?
  • What visualisation for what data?